package itea.bignews.dwr;

import itea.bignews.biz.AuthorizationManager;

import org.directwebremoting.WebContextFactory;

import com.javaeedev.openid.Authentication;

/**
 * 
 * @version $Id: Dwr.java 50 2009-09-07 13:39:17Z iteahere $
 * @author itea
 * @date 2009-9-5
 */
public abstract class Dwr {

	protected AuthorizationManager authorizationManager;
	
	protected boolean isLoggin() {
		return WebContextFactory.get().getSession().getAttribute("authentication") != null;
	}
	
	protected boolean isAuthorized(String module) {
		if(true) return true; // for devlope
		Authentication au = (Authentication)WebContextFactory.get().getSession().getAttribute("authentication");
		return au == null ? false :authorizationManager.isAuthorized(module, au.getEmail());
	}
	
	protected Authentication getAuthentication() {
		return (Authentication)WebContextFactory.get().getSession().getAttribute("authentication");
	}
	
	protected String getAuthenticationEmail() {
		Authentication au = (Authentication)WebContextFactory.get().getSession().getAttribute("authentication");
		return au == null ? null : au.getEmail();
	}
	
	protected String getAuthenticationIdentity() {
		Authentication au = (Authentication)WebContextFactory.get().getSession().getAttribute("authentication");
		return au == null ? null : au.getIdentity();
	}
	
	public void setAuthorizationManager(AuthorizationManager authorizationManager) {
		this.authorizationManager = authorizationManager;
	}
}
